package org.ziegler.log.analysis.resultHandler;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.lang3.StringUtils;

import org.ziegler.log.analysis.LogCore;
import org.ziegler.log.analysis.core.SplitColumn;

public class UnknownErrResultHandler implements ResultHandler {

    /** 为解析出key的日志 */
    private final List<String> unknownError = new ArrayList<>();

    @Override
    public void addResult(SplitColumn splitColumn) {
        if (StringUtils.isBlank(splitColumn.getKey())) {
            if (!unknownError.contains(splitColumn.getStr())) {
                unknownError.add(splitColumn.getStr());
            }
        }
    }

    @Override
    public void output() {
        LogCore.info("Unknown Error. num = " + unknownError.size());
        unknownError.stream().limit(100).forEach(err -> LogCore.log(err));
    }

}
